package com.igd.business.dao.impl;

import java.sql.SQLException;
import java.util.List;

import com.igd.business.dao.IUserDao;
import com.igd.exceptions.IgdException;
import com.igd.pojo.vo.PageList;
import com.igd.security.Resources;
import com.igd.security.Roles;
import com.igd.security.User;
 /**
 * @version  1.0
 *
 * @author   QIAOYU
 *
 * @date     2013-6-24
 *
 * @description	 用户与权限信息Dao接口实现类
 */

public class IUserDaoImpl extends IBaseDaoImpl implements IUserDao{
	
	private final String GET_USER_INFO_SQL = "user.getUserInfo";
	
	private final String GET_USER_ROLE_INFO_SQL = "user.getUserRole";
	
	private final String GET_USER_ROLE_RESOURCES_SQL = "user.getRoleResource";
	
	private final String GET_ALL_USER_INFO_SQL = "user.getAllUserInfo";
	
	private final String GET_ALL_USER_COUNT_SQL = "user.getUserCount";
	
	private final String INSERT_UER_INFO_SQL = "user.insertUserInfo";
	
	private final String DELETE_USER_INFO_SQL = "user.delUserInfo";
	
	private final String UPDATE_USER_INFO_SQL = "user.updUserInfo";
	
	public void updUser(User user) throws SQLException, IgdException {
		
		this.update(UPDATE_USER_INFO_SQL, user);
	}
	
	public void deleteUserInfo(User user) throws SQLException, IgdException {
		
		this.delete(DELETE_USER_INFO_SQL, user);
	}

	public User insertUserInfo(User user) throws SQLException, IgdException {
		
		this.save(INSERT_UER_INFO_SQL, user);
		
		return user;
	}
	
	public User queryUser(User user) throws SQLException, IgdException {

		return this.queryForObject(GET_USER_INFO_SQL,user);

	}

	public List<Roles> queryUserRole(User user) throws SQLException, IgdException {
		
		return this.queryForList(GET_USER_ROLE_INFO_SQL,user,new Roles());

	}
	
	public List<Resources> queryRoleResource(User user) throws SQLException, IgdException {
		
		return this.queryForList(GET_USER_ROLE_RESOURCES_SQL,user,new Resources());
		
	}

	public List<User> queryAllUser(PageList pageList,User user) throws SQLException, IgdException {

		return this.queryForListPage(GET_ALL_USER_INFO_SQL,GET_ALL_USER_COUNT_SQL, pageList,user);

	}
}
